package com.cmccgz.udacs_landlord_webapp.main.peoplemanager;

import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.alibaba.android.vlayout.VirtualLayoutManager;
import com.alibaba.android.vlayout.layout.LinearLayoutHelper;
import com.cmccgz.baselibrary.base.BaseActivity;
import com.cmccgz.udacs_landlord_webapp.R;
import com.cmccgz.udacs_landlord_webapp.adapter.PeopleFuncAdapter;
import com.cmccgz.udacs_landlord_webapp.bean.PeopleFunc;
import com.cmccgz.udacs_landlord_webapp.main.peoplemanager.contract.PeopleContract;
import com.cmccgz.udacs_landlord_webapp.main.peoplemanager.presenter.PeoplePresenter;
import com.cmccgz.udacs_landlord_webapp.utils.ViewHelper;

import java.util.List;

/**
 * @author Denis
 * @ClassName: PeopleManagerActivity
 * @Description: 租客管理功能列表页
 * @date 2017/6/7 10:48
 */

public class PeopleManagerActivity extends BaseActivity implements PeopleContract.View,View.OnClickListener {
    private RecyclerView rv_func;
    private PeopleContract.Presenter presenter;
    private PeopleFuncAdapter peopleFuncAdapter;
    private ViewHelper mViewHelper;

    @Override
    protected int setLayoutId() {
        return R.layout.activity_people_manager;
    }

    @Override
    protected void initView() {
        rv_func = (RecyclerView) findViewById(R.id.rv_func);
        VirtualLayoutManager lm = new VirtualLayoutManager(this);
        rv_func.setLayoutManager(lm);
        DelegateAdapter adapter = new DelegateAdapter(lm);
        peopleFuncAdapter = new PeopleFuncAdapter(this, new LinearLayoutHelper(2), null);
        adapter.addAdapter(peopleFuncAdapter);
        rv_func.setAdapter(adapter);
        rv_func.addItemDecoration(new DividerItemDecoration(mContext, DividerItemDecoration.VERTICAL));
        new PeoplePresenter(this);
        presenter.initData();

    }

    @Override
    protected void initFragment() {

    }

    @Override
    protected void beforePermission() {
        mViewHelper = ViewHelper.instance(mContext);
        if (mViewHelper!=null) {
            mViewHelper.setTitle("租客管理");
            mViewHelper.setAllVisable(false);
            mViewHelper.setBackTextVisable(true);
        }
    }

    @Override
    protected int setSystemBarColorId() {
        return 0;
    }

    @Override
    public void setPresenter(PeopleContract.Presenter presenter) {
        this.presenter = presenter;
    }

    @Override
    public void getData(List<PeopleFunc> datas) {
        peopleFuncAdapter.setDatas(datas);
        peopleFuncAdapter.notifyDataSetChanged();

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.tv_back:
                PeopleManagerActivity.this.finish();
                break;
        }
    }
}
